package com.gz.controller;

import java.util.List;

import com.gz.common.ReceivingAddressService;
import com.gz.common.model.Receivingaddress;
import com.gz.common.model.User;
import com.gz.utils.Response;
import com.jfinal.core.Controller;

/**
 * 收货地址接口
 * 
 * @author 86173
 *
 */
public class ReceivingAddressController extends Controller {

	/**
	 * 	@param:用户id
	 *  	获得当前用户所有收货地址信息
	 *  	测试URL:http://localhost:8080/cms-api/Receiving/getAddressListByUser?id=1
	 *  author:px
	 *  @return:所有地址信息
	 */
	public void getAddressListByUser() {
		List<Receivingaddress> addressList = ReceivingAddressService.getService().getAddressListByUser(getParaToInt("id"));
		/*判断查询结果是否等于NULL或者记录为0*/
		if (addressList!=null&&addressList.size() > 0) {
			renderJson(Response.responseJson(1006, "成功", addressList));
		} else {
			renderJson(Response.responseJson(1007, "失败", addressList)); 
		}
	}
	
	/**
	 * @param:收货地址对象
	 * 	新增收货地址
	 * 测试URL:http://localhost:8080/cms-api/Receiving/addReceivingaddress?
	 * address.provinceid=18&address.cityid=215&address.areaid=1981
	 * &address.streetid=26810&address.username=绝爷&address.userphone=17373172136
	 * &address.useraddress=开福区汽车北站&address.userid=1
	 * author:px
	 * @return:msg
	 */
	public void addReceivingaddress() {
		try {
			Receivingaddress receivingaddress = this.getModel(Receivingaddress.class,"address");
			ReceivingAddressService.getService().addReceivingaddress(receivingaddress);
			renderJson(Response.responseJson(1004, "新增收货地址成功"));
		} catch (Exception e) {
			e.printStackTrace();
			renderJson(Response.responseJson(1005, "新增收货地址失败"));
		}
	}
	
	/**
	 * @param：传入参数userId
	 * 	查询收货地址
	 * 	测试URL:http://localhost:8080/cms-api/Receiving/getAddressListByUserTest?userId=2
	 * author:px
	 * return:user
	 */
//	public void getAddressListByUserTest() {
//		Integer userId=2;//getParaToInt("userId");
//		User user=null;
//		try {
//			user = ReceivingAddressService.getService().getAddressListByUserTest(userId);
//			renderJson(Response.responseJson(1006, "成功！",user));
//		} catch (Exception e) {
//			// TODO: handle exception
//			e.printStackTrace();
//			renderJson(Response.responseJson(1007, "错误！",user));
//		}
//	}
}
